package com.example.springboot.service;

import com.example.springboot.entity.events;
import com.example.springboot.mapper.EventMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EventService {
    @Autowired
    private EventMapper eventMapper;

    public List<events> findAllEvents() {
        return eventMapper.findAll();
    }

    public events findEventById(Long id) {
        return eventMapper.findById(id).orElse(null);
    }

    public int saveEvent(events event) {
        if (event.getEvent_id() == null) {
            return eventMapper.save(event);
        } else {
            return eventMapper.update(event);
        }
    }

    public void addevent(events event) {
        eventMapper.insert(event);
    }

    public void deleteEvent(Long id) {
        eventMapper.deleteById(id);
    }

    public List<events> getAllEventsByid(Long id) {
        return eventMapper.getAllEventsByid(id);
    }
}
